<?php 


namespace Home\Controller;
use Think\Controller;
class LoginController extends CommonController {
    public function index(){
       
        $question = D('verify')->Oneverify();

      	$this->assign('question',$question);

        $this->assign('title','登陆');

      	 $this->display();
    }
    public function checkData()
    {
        $verify = I('post.verify');
    	 // echo $verify;exit;
    	 if ($verify!=$_SESSION['answer']) {
            $arr = array(
                'error' => 1,
                'info' => '人类验证不通过'
                );
            echo json_encode($arr);
            exit;
        }
    if ($res = D('user')->checkLogin(I('post.email'),I('post.password'))) {
        // var_dump($res);
        // 
        $_SESSION['id']=$res['id'];

        $_SESSION['nickname']=$res['nickname'];

        $_SESSION['face']=$res['face'];

        $_SESSION['email']=$res['email'];

        $_SESSION['city']=$res['city'];


    	$arr = array(
                'error' => 0,
                'info' => '登陆成功'
                );
            echo json_encode($arr);
            exit;
        }else{
             $arr = array(
                'error' => 1,
                'info' => '邮箱或者密码错误'
                );
            echo json_encode($arr);
        }
    }
    public function loginout()
    {
        session_unset();
        session_destroy();
        $this->success('退出成功',U('home/index/index'));
    }
   }










 ?>